package jeconbond.experiment.market.resourcerelations;

import jeconbond.experiment.market.resourcerelations.generate.AntBasedAgentsCreator;
import jeconbond.experiment.market.resourcerelations.generate.BranchingProdAutomataGenerator;
import jeconbond.experiment.market.resourcerelations.generate.BrosnenEngineInitialiser;
import jeconbond.experiment.market.resourcerelations.generate.GoalGroupComplementaryBasedProfitCostGen;
import jeconbond.economic.resources.ResourceUtils;
import jeconbond.economic.systems.market.DefaultMarketRRSFactory;
import jeconbond.experiment.JEBExperimentFlow;
import jeconbond.experiment.generate.ProfitableNormFormGenerateDecorator;
import jeconbond.experiment.ui.reportage.EconomicContextER2CConverter;
import laboratoryQ.experiment.settings.IExperimentSettings;
import laboratoryQ.experiment.settings.ISettingsContainer;
import laboratoryQ.experiment.settings.ReflectionBasedSettingsContainer;
import laboratoryQ.experiment.ui.reportage.ExperimentReportage;
import laboratoryQ.flatness.Point;

public class MainCasinoRoyale {
	public static IExperimentSettings newSettings() {
		JEBExperimentFlow experimentFlow = new JEBExperimentFlow();
		
		GraigExperimentSettings settings = 
			new GraigExperimentSettings();
		
		settings.initialise();
		
		settings.stepSize = 100;
		settings.stepCount = 190;
		settings.agentsCount = 50;
		settings.initMoney = 50.0;
		settings.initResourceExceedPercent = 1.2;
		settings.antAgentCount = 7;
		
		settings.chainLength = 5;
		settings.branchesCount = 5;
		settings.postBranchCount = 0;

		settings.agentGreedPercent = 1.5;
		settings.produceProfit = 1.15;
		settings.concurrentPricePercent = 0.5;
		settings.observeCostsTraceLength = 15;
		
		settings.rrsFactory = new DefaultMarketRRSFactory();
		settings.resources = ResourceUtils.generateResources("r", 9);
		settings.experiment = experimentFlow; 
		settings.randomSeed = 0.0; 
		settings.zeroPoint = new Point(0.0, 0.0);
		
		settings.purchaseExceedDayBudget = settings.initMoney * settings.agentsCount / settings.stepSize;
		settings.purchaseExceedPassivePeriod = settings.stepSize;
		settings.purchaseExceedUseTrackLength = (int) (settings.stepSize * 1.5);
		settings.utiliseExceedPeriod = settings.stepSize;
		settings.selectPropositionsPart = 0.8;
		settings.feramonHistoryLength = 5;
		settings.setCommoditiesComplementaryGroupsPower(7.0);
		settings.setCommoditiesComplementaryGroups(new int[][] {
				new int[] { 0, 1, 2, 3 },
				new int[] { 4, 5, 6, 7, 8 }
		}); 
		settings.profitCostManagerFactory = GoalGroupComplementaryBasedProfitCostGen.FACTORY_INSTANCE;
		settings.goalResourceIndex = 0;
		settings.timeStepX = 100;
		settings.speculantPropCountMarketPart = 0.5;
		settings.speculantGoalValueMarketPart = 0.1;
		
		settings.validate();

		experimentFlow.automataGenerator =
				new ProfitableNormFormGenerateDecorator(new BranchingProdAutomataGenerator());
		experimentFlow.agentCreator = new AntBasedAgentsCreator();
		experimentFlow.engineInitialiser = new BrosnenEngineInitialiser();
		
		return settings;
	}

	public static ISettingsContainer newSettingsContainer() {
		ReflectionBasedSettingsContainer settingsCont = 
			new ReflectionBasedSettingsContainer(newSettings());
		settingsCont.sortFields(
				"stepSize",
				"stepCount",
				"agentsCount",
				
				"branchesCount",
				"postBranchCount",
				"chainLength",
				"antAgentCount",

				"purchaseExceedDayBudget",
				"purchaseExceedPassivePeriod",
				"purchaseExceedUseTrackLength",
				
				"produceProfit",
				"agentGreedPercent",
				"concurrentPricePercent",
				
				"speculantPropCountMarketPart",
				"speculantGoalValueMarketPart",
				"commoditiesAbstractGroupsPower",
				
				"initMoney",
				"initResourceExceedPercent",
				"observeCostsTraceLength",
				"randomSeed"
		);
		return settingsCont;
	}

	public static ExperimentReportage newExperimentReportage() {
		ISettingsContainer settingsContainer = newSettingsContainer();
		
		ExperimentReportage experimentReportage = 
			ExperimentReportage.newExperiment2componentReportage(
					settingsContainer,
					new EconomicContextER2CConverter("CasinoRoyale complementary")
			);
		return experimentReportage;
	}

	public static void main(String[] args) {
		ExperimentReportage experimentReportage = newExperimentReportage();
		experimentReportage.showReportageFrame(args);
	}
}
